﻿var index;
function layer_show(title, url, w, h, fix, shadeClose, closeBtn) {
    if (index != 0) {
        layer.close(index);
    }
    layer.closeAll();
    index = layer.open({
        type: 2,
        //skin: 'layui-layer-lan',
        title: title,
        shadeClose: true,
        shade: false,
        closeBtn: closeBtn,
        shade: [0.8, '#393D49'],
        maxmin: false, //开启最大化最小化按钮
        area: [w + 'px', h + 'px'],
        fix: fix,
        content: url, success: function (layero, index) {
            layer.iframeAuto(index);

        },
        end: function () {

        }
    });
}
function layer_showhtml()
{
    if (index != 0) {
        layer.close(index);
    }
    layer.closeAll();
    index = layer.open({
        type: 2,
        //skin: 'layui-layer-lan',
        title: title,
        shadeClose: shadeClose,
        shade: false,
        closeBtn: closeBtn,
        shade: [0.8, '#393D49'],
        maxmin: false, //开启最大化最小化按钮
        area: [w + 'px', h + 'px'],
        fix: fix,
        content: url,
        end: function () {

        }
    });
}
function layer_show1(title, url, w, h, fix, shadeClose, closeBtn) {
    if (index != 0) {
        layer.close(index);
    }
    layer.closeAll();
    index = layer.open({
        type: 2,
        //skin: 'layui-layer-lan',
        title: [title, 'background:#499df3;color:#fff;'],
        shadeClose: true,
        shade: false,
        closeBtn: closeBtn,
        shade: [0.8, '#393D49'],
        maxmin: false, //开启最大化最小化按钮
        area: ['500px', '500px'],
        offset: '100px',
        fix: fix,
        content: url,
        success: function (layero, index) {
            layer.iframeAuto(index);

        },
        end: function () {

        }
    });
}
function login_show(title, url, w, h, fix, shadeClose, closeBtn)
{
    var newurl = url;
    jQuery.ajax({
        url: '/User/CheckLogin',
        type: 'post',
        offset: '100px',
       // async: false,
       // area: [w + 'px', h + 'px'],
       /* success: function (layero, index) {
            layer.iframeAuto(index);

        },*/
        success: function (data) {
            //layer.iframeAuto(index);

            if (data != "True" && data != true) {
                var url = "/User/Login";
                layer_show(false, url, 500, 400);
            } else {
                layer_show1(title, newurl, w, h, fix, shadeClose, closeBtn);
            }
        }
    });
}

//iFrame元素赋值
function layer_showParameter(title, content, w, h, posValue) {
    layer.closeAll();
    index = layer.open({
        type: 2,
        title: title,
        shade: 0.8,
        area: [w, h],
        content: content, 
        success: function (layero, index) {
            var IframePposValue = $("#posValue", layero.find("iframe")[0].contentWindow.document);
            IframePposValue.attr("value", posValue);
        }
    });
}

//新增视角页面层
function layer_page(title, content, w, h) {
    index= layer.open({
        title: title,
        type: 1,
        shade: false,
        //skin: 'layui-layer-rim', //加上边框
        area: [w, h], //宽高
        content: content,
        success: function (layero, index) {
            $("#posThumbImg").attr("src", $("#hid_posThumbImg").val());
            ////alert($("#posThumbImg").width());
            //    var x = 400; //填入目标图片宽度 
            //    var y = 240; //填入目标图片高度 
            //    var w = $("#posThumbImg").width(), h = $("#posThumbImg").height();//获取图片宽度、高度 
            //    if (w > x) { //图片宽度大于目标宽度时 
            //        var w_original = w, h_original = h;
            //        h = h * (x / w); //根据目标宽度按比例算出高度 
            //        w = x; //宽度等于预定宽度 
            //        if (h < y) { //如果按比例缩小后的高度小于预定高度时 
            //            w = w_original * (y / h_original); //按目标高度重新计算宽度 
            //            h = y; //高度等于预定高度 
            //        }
            //    }
            //   // alert(w + ":" + h);
            //    $("#posThumbImg").attr({ width: w, height: h });
        }
    })
}


//登录
function login() {
    
    jQuery.ajax({
        url: '/User/CheckLogin',
        type: 'post',
        async: false,
        success: function (data) {
            if (data != "True" && data != true) {
                var url = "/User/Login";
                layer_show(false, url, 500, 400);
            } else {
                if (getCookie("Cookie_BIM_OperationTip") != "1") {
                    index = layer.open({
                        type: 2,
                        title: false,
                        shade: [0.8, '#393D49'],
                        area: ['600px', '500px'],
                        content: '/User/Showtips',
                        cancel: function () {
                            setCookie("Cookie_BIM_OperationTip", "1");
                        }
                    });
                }
            }
        }
    });
}
//注销
function loginout() {
    alert("要注销吗，还没做呢..");
}

//JS操作cookies方法!
//写cookies
function setCookie(name, value) {
    var Days = 300;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
//读取cookies
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) {
        return unescape(arr[2]);
    }
    else
        return null;
}
//删除cookies
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}


function layer_show_popWinUrl(title, url, w, h) {
    if (index != 0) {
        layer.close(index);
    }
    layer.closeAll();
    layer.open({
        type: 2,
        shade: false,
        title: title, //不显示标题
        content: url,
        fix: true,
        shadeClose: true,
        maxmin: false, //开启最大化最小化按钮
        area: [w + 'px', h + 'px'],

    });
}
